package main

import (
	"fmt"
	"os/exec"
	"strings"
)

type etcdInfo struct {
	id          string
	status      string
	name        string
	peerAddrs   string
	clientAddrs string
}

func scrapeEtcdInfos() ([]etcdInfo, error) {
	var etcdInfos []etcdInfo
	getEtcdMemberListCmd := exec.Command("bash", "-i", "-c", "etcd_v3 member list")
	getEtcdMemberListCmdOut, _ := getEtcdMemberListCmd.Output()
	linesList := strings.Split(string(getEtcdMemberListCmdOut), "\n")[7:10]
	for _, line := range linesList {
		fruits := strings.Split(line, ",")
		etcdInfos = append(etcdInfos, etcdInfo{
			id:          fruits[0],
			status:      fruits[1],
			name:        fruits[2],
			peerAddrs:   fruits[3],
			clientAddrs: fruits[4],
		})
	}
	return etcdInfos, nil
}

func main() {
	etcdInfos, _ := scrapeEtcdInfos()
	fmt.Println(etcdInfos)
}
